package cn.neusoft.controller;

import cn.neusoft.query.EmpQuery;
import cn.neusoft.pojo.Emp;
import cn.neusoft.result.PageBean;
import cn.neusoft.service.IEmpService;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/emp")
public class EmpController {

    @Autowired
    IEmpService empService;

    @PostMapping
    public String add(@RequestBody Emp emp){
        int add = empService.add(emp);
        return add>0?"success":"fail";
    }

    @PutMapping
    public String update(@RequestBody Emp emp){
        int update = empService.update(emp);
        return update>0?"success":"fail";
    }

    @DeleteMapping("/{empno}")
    public String del(@PathVariable("empno") Integer empno){
        int del = empService.del(empno);
        return del>0?"success":"fail";
    }

    @GetMapping("/all")
    public List<Emp> getAll(){
        return empService.getAll();
    }

    @GetMapping("/{empno}")
    public Emp getById(@PathVariable("empno") Integer empno){
        return empService.getById(empno);
    }

    @PostMapping("/page")
    public PageBean<Emp> getByPage(@RequestBody EmpQuery empQuery){
        return empService.getByPage(empQuery);
    }
}
